package com.soft.dao;

import com.soft.pojo.User;
import com.soft.utils.DBUtil;

import java.util.List;

public class UserDAO {
    public void insertUser(User user) {
        DBUtil.excute("insert into user(username,password,gender,email,telephone,introduce) values(?,?,?,?,?,?)",
                user.getUsername(), user.getPassword(), user.getGender(), user.getEmail(), user.getTelephone(), user.getIntroduce());
    }

    public User selectUserByUsernameAndPassword(User user) {
        List<User> users = DBUtil.query("select * from user where username=? and password=?", User.class, user.getUsername(), user.getPassword());
        if (users.size()>0){
            return users.get(0);
        }
        return null;
    }

    public boolean selectUserByUsername(User user) {
        List<User> users = DBUtil.query("select * from user where username=? ", User.class, user.getUsername());
        return users.size() > 0;
    }
}
